<?php

	if(!defined('YMT')) exit;
	
	/**
	 * @package Yomm
	 * @author bsuter
	 *
	 */
	Class Yomm_Library_Convert {
		
		public static function arrayToObject($array)
		{
			if(!is_array($array) || count($array) == 0) return $array;
			
			$return = new stdClass();
			
			foreach ($array as $k => $v)
			{
				if(is_array($v))
				{
					$return->$k = Yomm_Library_Convert::arrayToObject($v);
				}
				else {
					$return->$k = $v;
				}
			}
		 
			return $return;
		}
		
		public static function objectToArray($obj)
		{ 
			if(!is_object($obj) || is_null($obj)) return $obj;
			
		    $_arr = is_object($obj) ? get_object_vars($obj) : $obj; 
		    foreach ($_arr as $key => $val)
		    { 
		        $val = (is_array($val) || is_object($val)) ? Yomm_Library_Convert::objectToArray($val) : $val; 
		        $arr[$key] = $val; 
		    } 
		    return $arr; 
		}
		
		/* +++ */
		
		public static function textEncode($text)
		{
			//return htmlentities(utf8_decode($text), ENT_QUOTES);
			return str_replace(array(
				'ü','ö','ä',"'"
			), array(
				'&uuml;', '&ouml;', '&auml;', '&#039;'
			), nl2br($text));
		}
		
		public static function textDecode($text)
		{
			return html_entity_decode($text);
		}
		
		public static function entitiesEncode($text)
		{
			return htmlentities(utf8_decode($text), ENT_QUOTES);
		}
		
		public static function brToNl($string)
		{ 
			return preg_replace('`<br(?: /)?>([\\n\\r])`', '$1', $string); 
		}
		
		
		
	}